<!--借还日志-->
<html>
<head>
    <meta charset="utf-8">
    <title>借还日志</title>
    <!--<link rel="stylesheet" type="text/css" href="css/common.css">-->
    <!--<link rel="stylesheet" href="css/search.css">-->
    <style>
        /*分页样式*/
        .pageNum {
            width: 100%;
            overflow: hidden;
        }


        .pageNum ul li {
            list-style: none;
            width: 40px;
            height: 40px;
            float: left;
            border: 1px solid #eee;
            margin-right: 10px;
            text-align: center;
            line-height: 40px;
        }
        .pageNum ul li.curPage {
            background-color: #ffc900;
        }
        .pageNum ul li a {
            width: 100%;
            height: 100%;
            color: #000;
            font-size: 14px;
        }
        .pageNum ul .threeword {
            width: 75px;
        }
        body{
            background-color: rgb(240,242,245);
        }
        .ssk{
            margin: 10px auto;
            text-align: center;
        }
    </style>

</head>
<body>

<div class="ssk">
    <form   method="post" class="form-inline"  id="searchform">
        <div class="input-group">
            <input type="text" placeholder="输入图书号"  id="search" name="searchWord" class="form-control" >
            <span class="input-group-btn">
                    <input type="submit" value="搜索" class="btn btn-default" id="btn">
            </span>
        </div>
    </form>
    <script>
        //入口函数，查询数据库显示借还日志

        $(function () {
            load(1,10,'');
        })
        $("#searchform").submit(function () {
            var val=$("#search").val();
            // if(val==''){
            //     alert("请输入关键字");
            //     return false;
            // }
            var reg=/^[0-9]{1,11}$/
            var flag = reg.test(val);
            if(flag){
                load(1,10,val);
                return false;
            }
            alert("未查到图书号");
            //如果搜索的内容不是int型，就查询所有数据
            load(1,10,'');
            return false;
        })

        function load(currentPage,rows,searchRoute) {
            //页面定位
            scroll(0,0);
            $.ajax({
                type:"post",
                dataType:"json",
                url:"user/lendRecord",
                data:{"currentPage":currentPage,"rows":rows,"text":searchRoute},//请求参数为：1.当前页  2.每页的条数 3.模糊查询数据,第一次进入此页面$("#search").val()为空
                success:function (data) {//data为RecordPageBean对象
                    //**********************翻页*****************************/
                    var lis='',begin,end;
                    lis+='<li onclick="javascript:load(1,'+data.rows+',\''+searchRoute+'\')"><a href="#">首页</a></li>\n' +
                        ' <li class="threeword"onclick="javascript:load('+((data.currentPage-1)<=1?1:(data.currentPage-1))+','+data.rows+',\''+searchRoute+'\')"><a href="#">上一页</a></li>';
                    if(data.totalPage<=10)
                    {
                        begin=1;
                        end=data.totalPage;
                    }else{
                        //总页数大于10
                        begin=data.currentPage-5;
                        if(begin<1)
                        {
                            begin=1;
                        }
                        end=currentPage+4;
                        if(currentPage<=6)
                        {
                            end=10
                        }
                        if(end>data.totalPage)
                        {
                            end=data.totalPage;
                        }

                    }
                    for (var i = begin; i <=end ; i++) {
                        if(i==currentPage)
                        {
                            lis+='<li class="curPage"onclick="javascript:load('+i+','+data.rows+',\''+searchRoute+'\')"><a href="#">'+i+'</a></li>';
                        }else
                        {
                            lis+='<li onclick="javascript:load('+i+','+data.rows+',\''+searchRoute+'\')"><a href="#">'+i+'</a></li>';
                        }

                    }
                    lis+='  <li class="threeword" onclick="javascript:load('+((data.currentPage+1)>=data.totalPage?data.totalPage:(data.currentPage+1))+','+data.rows+',\''+searchRoute+'\')"><a href="#">下一页</a></li>\n' +
                        '                            <li class="threeword" onclick="javascript:load('+data.totalPage+','+data.rows+',\''+searchRoute+'\')"><a href="#">末页</a></li>'
                    $("#jump_page").html(lis)
                    //**********************翻页*****************************/

                    //**********************日志信息*****************************/
                    var route_li='';
                    $.each(data.list,function (index,ele) {

                        var lend_date=format(ele.lend_date);
                        var back_date=format(ele.back_date);
                        if(!ele.back_date)
                            route_li+='<tr><td>'+ele.sernum+'</td><td>'+ele.book_id+'</td><td>'+ele.reader_id+'</td><td>'+lend_date+'</td><td></td><td><a class="jump2" name="user/deleteOne?sernum='+ele.sernum+'"><button type="button" class="btn btn-danger btn-xs">删除</button></a></td></tr>';
                        else
                            route_li+='<tr><td>'+ele.sernum+'</td><td>'+ele.book_id+'</td><td>'+ele.reader_id+'</td><td>'+lend_date+'</td><td>'+back_date+'</td><td><a class="jump2" name="user/deleteOne?sernum='+ele.sernum+'"><button type="button" class="btn btn-danger btn-xs">删除</button></a></td></tr>';
                    })

                    $("tbody:eq(0)").html(route_li);
                    $(".jump2").click(function () {
                        setCookies($(this).prop("name"));
                        $("#middle").load($(this).prop("name"));
                    });
                    //**********************日志信息*****************************/

                    //总页数,总条数
                    $("#page").html(data.totalPage);
                    $("#count").html(data.totalCount);
                }
            })
        }
        function mySubmit(flag){
            return flag;
        }
        function format(object) {
            var year = new Date(object).getFullYear(); //获取完整的年份(4位,1970-????)
            var month = new Date(object).getMonth() + 1; //获取当前月份(0-11,0代表1月)
            var day = new Date(object).getDate(); //获取当前日(1-31)
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            var dateString =  year + "-" + month + "-" + day;
            return dateString;

        }

    </script>
</div>
<div style="position: relative;top: 10%">
   <!-- <c:if test="${!empty succ}">
        <div class="alert alert-success alert-dismissable">
            <button type="button" class="close" data-dismiss="alert"
                    aria-hidden="true">
                &times;
            </button>
                ${succ}
        </div>
    </c:if>
    <c:if test="${!empty error}">
        <div class="alert alert-danger alert-dismissable">
            <button type="button" class="close" data-dismiss="alert"
                    aria-hidden="true">
                &times;
            </button>
                ${error}
        </div>
    </c:if>-->
</div>
<div class="panel panel-default" style="width: 90%;margin-left: 5%">
    <div class="panel-heading">
        <h3 class="panel-title">
            借还日志
        </h3>
    </div>
    <div class="panel-body">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>流水号</th>
                <th>图书号</th>
                <th>读者证号</th>
                <th>借出日期</th>
                <th>归还日期</th>
                <th>删除</th>
            </tr>
            </thead>
            <tbody>

                <!--<tr>
                    <td><c:out value="${alog.sernum}"></c:out></td>
                    <td><c:out value="${alog.bookId}"></c:out></td>
                    <td><c:out value="${alog.readerId}"></c:out></td>
                    <td><c:out value="${alog.lendDate}"></c:out></td>
                    <td><c:out value="${alog.backDate}"></c:out></td>
                    <td><a href="deletebook.html?bookId=<c:out value="${alog.sernum}"></c:out>"><button type="button" class="btn btn-danger btn-xs">删除</button></a></td>
                </tr>
-->
            </tbody>
        </table>
        <div class="page_num_inf">
            <i></i> 共
            <span id="page"></span>页<span id="count"></span>条
        </div>
        <div class="pageNum">
            <ul id="jump_page">

            </ul>
        </div>
    </div>
</div>

</body>
</html>
